﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Interop;
namespace Congducsan
{
    class ClsTc
    {
        public AcadApplication mvarobjApp;
        public String Huongdong;
        //'Kich thuoc
        public object ArrDimT;
        public object ArrDimD;
        public object ArrDimV;
        public object ArrDimTdT;
        public object ArrDimTdD;
        //'Trac ngang
        public object ArrTaluyTren;
        public object ArrTaluyDuoi;
        public object ArrTaluyTren1;
        public object ArrTaluyDuoi1;
        public object ArrTaluyTren2;
        public object ArrTaluyDuoi2;
        public object ArrTd;
        public Boolean BaccapGc;
        public Boolean isSanGc;
        public long Sogotieunang;
        public Boolean CkTrongTc;
        //'Duong tim
        public long idDuongtim;
        public object dataDuongtim;
        //'Op mai taluy
        //'Mat bang
        public long idTaluyTren;
        public long idTaluyDuoi;
        public long idTaluy;
        //'Mat chieu
        public long idTaluyTrai;
        public long idTaluyPhai;
        public long idTaluyChieu;
        public Double RongtaluyB2;
        public Double Caotaluyh2;
        private Double Xvao;
        private Double Yvao;
        private Double Xra;
        private Double Yra;
        private long mvarBnSobac;
        private Double mvarBnRong;
        private Double mvarBnCao;
        private Double mvarDocm;
        private Double mvarDoci;
        private Double mvarCaoH1;
        private Double mvarCaoH2;
        private Double mvarDaymong;
        private Double mvarDaytuong;
        private Double mvarMrongtuong;
        private Double mvarMrongT;
        private Double mvarMrongb4;
        private Double mvarGoca;
        private Double mvarGoca1;
        private Double mvarGoca2;
        private Double mvarMorongm1;
        private Double mvarMorongm2;
        private Double mvarDaysan;
        private Double mvarSauCk;
        private Double mvarDayCk;
        private Double mvarMorCk;
        private Double mvarKhDien;
        private Double mvarDayong;
        private Double mvarSoday;
        private Double mvarCachkhoangday;
        private int mvarTraiphai;
        private Boolean mvarKtVuongGoc;
        private int mvarTcNt;
        private Double m_DuoiTc;
        private Double mvarTana;
        private Double mvarLopdem;
        private Double mvarTlB;
        private String mvarTl;
        private int mvarTlT;
        private String mvarVlTc;
        private Double mvarKhauDienB;
        private Double mvarBedayT2;
        private Double mvarBedayT4;
        private long mvarSocua;
        private Double mvarGocxien;
        private Double mvarHsKc;
        private Boolean mvarGotieunang;
        private Double mvarRongGotieunang;
        private Double mvarRongdGotieunang;
        private Double mvarCaoGotieunang;
        private Double mvarDaiGotieunang;
        private Double mvarCkGotieunang;
        const double Pi = 3.14159265358979;
        private ClsCommon Com;
        private Double mvarCaochuG;
        private Double mvarCaochuT;
        public object Tdden;

        public Double CaochuG
        {
            set { mvarCaochuG = value; }
            get { return mvarCaochuG * TlDim(); }
        }
        public Double CaochuT
        {
            set { mvarCaochuT = value; }
            get { return mvarCaochuT * TlDim(); }
        }
        private void Class_Terminate()
        {
            //Set Com = Nothing;
        }
        private void Class_Initialize()
        {
            //Set Com = New ClsCommon;
        }
        //'******************** THUOC TINH - PROPERTIES ******************
        public Boolean Gotieunang
        {
            set { mvarGotieunang = value; }
            get { return mvarGotieunang; }
        }
        public Double RongGotieunang
        {
            set { mvarRongGotieunang = value; }
            get { return mvarRongGotieunang; }
        }
        public Double RongdGotieunang
        {
            set { mvarRongdGotieunang = value; }
            get { return mvarRongdGotieunang; }
        }
        public Double CaoGotieunang
        {
            set { mvarCaoGotieunang = value; }
            get { return mvarCaoGotieunang; }
        }
        public Double DaiGotieunang
        {
            set { mvarDaiGotieunang = value; }
            get { return mvarDaiGotieunang; }
        }
        public Double CkGotieunang
        {
            set { mvarCkGotieunang = value; }
            get { return mvarCkGotieunang; }
        }
        public Double BnCao
        {
            set { mvarBnCao = value; }
            get { return mvarBnCao; }
        }
        public Double BnRong
        {
            set { mvarBnRong = value; }
            get { return mvarBnRong; }
        }
        public long BnSobac
        {
            set { mvarBnSobac = value; }
            get { return mvarBnSobac; }
        }
        public Double HsKc
        {
            set { mvarHsKc = value; }
            get { return mvarHsKc; }
        }
        public Double GocXien
        {
            set { mvarGocxien = value; }
            get { return mvarGocxien * Pi / 180; }
        }
        public Double Gocdoi
        {
            get { return 0.5 * Pi - GocXien; }
        }
        public long Socua
        {
            set { mvarSocua = value; }
            get { return mvarSocua; }
        }
        public Double BedayT4
        {
            set { mvarBedayT4 = value; }
            get { return mvarBedayT4; }
        }
        public Double BedayT2
        {
            set { mvarBedayT2 = value; }
            get { return mvarBedayT2; }
        }
        public Double KhauDienB
        {
            set { mvarKhauDienB = value; }
            get { return mvarKhauDienB; }
        }
        public String VlTc
        {
            set { mvarVlTc = value; }
            get { return mvarVlTc; }
        }
        public Double Cachkhoangday
        {
            set { mvarCachkhoangday = value; }
            get { return mvarCachkhoangday; }
        }
        public Double Soday
        {
            set { mvarSoday = value; }
            get { return mvarSoday; }
        }
        public Double Dayong
        {
            set { mvarDayong = value; }
            get { return mvarDayong; }
        }
        public Double KhDien
        {
            set { mvarKhDien = value; }
            get { return mvarKhDien; }
        }
        public Double DayCk
        {
            set { mvarDayCk = value; }
            get
            {
                if (KTVuongGoc)
                {
                    return mvarDayCk / Math.Sin(GocXien);
                }
                else
                {
                    return mvarDayCk;
                }
            }
        }
        public Double SauCk
        {
            set { mvarSauCk = value; }
            get { return mvarSauCk; }
        }
        public Double Daysan
        {
            set { mvarDaysan = value; }
            get { return mvarDaysan; }
        }
        public Double Morongm2
        {
            set { mvarMorongm2 = value; }
            get { return mvarMorongm2; }
        }
        public Double Morongm1
        {
            set { mvarMorongm1 = value; }
            get { return mvarMorongm1; }
        }
        public Double Goca
        {
            set { mvarGoca = value; }
            get { return mvarGoca; }
        }
        public Double Goca1
        {
            set { mvarGoca1 = value; }
            get { return mvarGoca1 / 180 * Pi; }
        }
        public Double Goca2
        {
            set { mvarGoca2 = value; }
            get { return mvarGoca2 / 180 * Pi; }
        }
        public Double Mrongtuong
        {
            set { mvarMrongtuong = value; }
            get { return mvarMrongtuong; }
        }
        public Double MrongT
        {
            set { mvarMrongT = value; }
            get { return mvarMrongT; }
        }
        public Double Mrongb4
        {
            set { mvarMrongb4 = value; }
            get { return mvarMrongb4; }
        }
        public Double Daytuong
        {
            set { mvarDaytuong = value; }
            get { return mvarDaytuong; }
        }
        public Double Tana1X
        {
            get { return Math.Tan(Goca1) / (1 - Traiphai * Math.Tan(Goca1) * Math.Tan(Gocdoi)); }
        }
        public Double Tana2X
        {
            get { return Math.Tan(Goca2) / (1 + Traiphai * Math.Tan(Goca2) * Math.Tan(Gocdoi)); }
        }
        public Double DaytuongT
        {
            get
            {
                if (KTVuongGoc)
                {
                    if (Traiphai == -1)
                    {
                        return Daytuong / Math.Cos(Goca1 + GocXien - Pi / 2) * Math.Sin(GocXien);
                        
                    }
                    else
                    {
                        return Daytuong / Math.Cos(Goca1 - GocXien + Pi / 2) * Math.Sin(GocXien);
                    }
                }
                else
                {
                    return Daytuong;
                }
            }
        }
        public Double DaytuongD
        {
            get
            {
                if (KTVuongGoc)
                {
                    if (Traiphai == -1)
                    {
                        return Daytuong / Math.Cos(Goca2 - GocXien + Pi / 2) * Math.Sin(GocXien);
                    }
                    else
                    {
                        return Daytuong / Math.Cos(Goca2 + GocXien - Pi / 2) * Math.Sin(GocXien);
                    }
                }
                else
                {
                    return Daytuong;
                }
            }
        }
        public Double Daymong
        {
            set { mvarDaymong = value; }
            get { return mvarDaymong; }
        }
        public Double CaoH2
        {
            set { mvarCaoH2 = value; }
            get { return mvarCaoH2; }
        }
        public Double Caoh1
        {
            set { mvarCaoH1 = value; }
            get { return mvarCaoH1; }
        }
        public Double Doci
        {
            set { mvarDoci = value; }
            get { return mvarDoci; }
        }
        public Double Docm
        {
            set { mvarDocm = value; }
            get { return mvarDocm / Math.Cos(Gocdoi); }
        }
        public int TcNt
        {
            set { mvarTcNt = value; }
            get { return mvarTcNt; }
        }
        public int Traiphai
        {
            set { mvarTraiphai = value; }
            get { return mvarTraiphai; }
        }
        public Boolean KTVuongGoc
        {
            set { mvarKtVuongGoc = value; }
            get { return mvarKtVuongGoc; }
        }
        public Double MorCk
        {
            set { mvarMorCk = value; }
            get { return mvarMorCk; }
        }
        public Double DuoiTc
        {
            set { m_DuoiTc = value; }
            get { return m_DuoiTc; }
        }
        public Double Tana
        {
            set { mvarTana = value; }
            get { return mvarTana; }
        }
        public Double Lopdem
        {
            set { mvarLopdem = value; }
            get { return mvarLopdem; }
        }
        public Double TlB
        {
            set { mvarTlB = value; }
            get { return mvarTlB; }
        }
        public String Tl
        {
            set { mvarTl = value; }
            get { return mvarTl; }
        }
        public int TlT
        {
            set { mvarTlT = value; }
            get { return mvarTlT; }
        }
        public Double Cosa
        {
            get { return Math.Sqrt(1 / (1 + Tana * Tana)); }
        }
        public Double Sina
        {
            get { return Math.Sqrt((1 - Cosa * Cosa)); }
        }
        public Double BenTc1
        {
            get { return Caoh1 / Doci; }
        }
        public Double BenTc2
        {

            get { return CaoH2 / Doci; }
        }
        public Double Rongbaccuoi
        {

            get { return Mrongtuong + DaiTC() - MrongT - (BnSobac - 1) * BnRong; }
        }
        public Double TlDim()
        {
            return Com.HsTl(Double.Parse(Tl), TlT);
        }
        //'Chieu dai tuong canh ung voi truong hop goc mo = 0
        public Double DaiTC()
        {
            Double Caoh1p;
            if (MrongT >= Mrongtuong)
            {
                Caoh1p = Caoh1 - (MrongT - Mrongtuong) / Docm;
                return Docm * (Caoh1p - CaoH2) / (1 - Docm * Tana) + (MrongT - Mrongtuong);
            }
            else
            {
                Caoh1p = Caoh1 + (Mrongtuong - MrongT) * Tana;
                return Docm * (Caoh1p - CaoH2) / (1 - Docm * Tana);
            }
        }
        public Double MoTc
        {
            get { return DaiTC() * Math.Tan(Goca * Pi / 180); }
        }
        public Double MoTc1
        {
            get { return DaiTC() * Tana1X; }
        }
        public Double MoTc2
        {
            get { return  DaiTC() * Tana2X; }
        }
        public Double BeRong(Boolean Conghop)
        {
            {
                if (Conghop)
                {
                    if (TcNt == 0)
                    {
                        return Socua * KhauDienB + 2 * BedayT2 + (Socua - 1) * BedayT4;
                    }
                    else
                    {
                        return Socua * KhauDienB + (Socua - 1) * BedayT4;
                    }
                }
                else
                {
                    return (KhDien + 2 * Dayong) * Soday + Cachkhoangday * (Soday - 1) - 2 * Dayong + 2 * Mrongb4;
                }
            }
        }
        public Double RongSanTren(Boolean Conghop)
        {
            return BeRong(Conghop) / 2 + MoTc1 + DaytuongT + (BenTc2 + Morongm1);
        }
        public Double RongSanDuoi(Boolean Conghop)
        {
            return BeRong(Conghop) / 2 + MoTc2 + DaytuongD + (BenTc2 + Morongm1);
        }
        public Double RongSanT(Boolean Conghop)
        {
            return RongSanTren(Conghop) + RongSanDuoi(Conghop);
        }
        public Double RongCkT(Boolean Conghop)
        {
            return RongSanT(Conghop) + 2 * MorCk;
        }
        public String HatchName()
        {
            switch (VlTc.Substring(0, 3))
            {
                case "BTM": return "ansi31";
                case "DHX": return "Honey";
                default: return "Gravel";
            }
        }
        String MaterialName()
        {
            switch (VlTc)
            {
                case "BTM100":
                    return "Bê tông M100";

                case "BTM150":
                    return "Bê tông M150";

                case "BTM200":
                    return "Bê tông M200";

                case "BTM250":
                    return "Bê tông M250";

                case "BTM300":
                    return "Bê tông M300";

                case "DHMM75":
                    return "Đá hộc miết mạch M75";

                default:
                    return "Đá hộc xây vữa M100";
            }
        }

        //'************THKL************
        Double Diengiai(Double giatri, int phanthapphan = 2)
        {
            //'Ham dung de dien giai cach tinh toan khoi luong
            return Math.Round(giatri * 0.001 * Com.HsTl(Double.Parse(Tl), 1 - TlT), phanthapphan);
        }
        Double HsKichthuoc()
        {
            return 0.001 * Com.HsTl(Double.Parse(Tl), 1 - TlT);
        }
        //'Tuong canh
        Double VTc()
        {
            Double mVtc=new double(); 
            long n, i;
            Double X1, X2;
            Double deltax1, deltax2, DeltaX;
            Double Caohi, Si;
            X1 = Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi));
            X2 = Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi));
            n = 200;
            deltax1 = X1 / n;
            deltax2 = X2 / n;
            DeltaX = DaiTC() * Math.Sin(GocXien) / n;
            for (i = 0; i < n; i++)
            {
                Caohi = CaoH2 + i * deltax1 / X1 * (Caoh1 - CaoH2);
                Si = (DaytuongT / Math.Sin(GocXien) + DaytuongT / Math.Sin(GocXien) + Caohi / Doci) * Caohi / 2;
                mVtc = mVtc + Si * DeltaX;
                Caohi = CaoH2 + i * deltax2 / X2 * (Caoh1 - CaoH2);
                Si = (DaytuongD / Math.Sin(GocXien) + DaytuongD / Math.Sin(GocXien) + Caohi / Doci) * Caohi / 2;
                mVtc = mVtc + Si * DeltaX;
                

            }
            mVtc = mVtc + (DaytuongT + DaytuongT + BenTc1) * Caoh1 / 2 * Mrongtuong;
            mVtc = mVtc + (DaytuongD + DaytuongD + BenTc1) * Caoh1 / 2 * Mrongtuong;
            return Math.Round(mVtc * Math.Pow(HsKichthuoc(),3), 2);
        }
        Double VTcGTCC()
        {
            Double S1, S2;
            Double mVtc=new double();
            S1 = (Diengiai(Daytuong) + Diengiai(Daytuong + BenTc1)) * Diengiai(Caoh1) / 2;
            S2 = (Diengiai(Daytuong) + Diengiai(Daytuong + BenTc2)) * Diengiai(CaoH2) / 2;
            if ((GocXien == Pi / 2) && Goca1 == Goca2 )
            {
                mVtc = 2 * (S1 + S2) / 2 * Diengiai(DaiTC()) / Math.Round(Math.Cos(Goca1), 3);
                if (Mrongtuong > 0 )
                {
                    mVtc = mVtc + 2 * S1 * Diengiai(Mrongtuong);
                }
                
            }
            else
            {
                mVtc = mVtc + (S1 + S2) / 2 * Diengiai((Double)Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi))) / Math.Round(Math.Cos(Goca1), 3);
                mVtc = mVtc + (S1 + S2) / 2 * Diengiai((Double)Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi))) / Math.Round(Math.Cos(Goca2), 3);
                if (Mrongtuong > 0)
                {
                    mVtc = mVtc + 2 * S1 * Diengiai(Mrongtuong);
                }
            }
           
            return Math.Round(mVtc, 2);
        }
        String VTcGTCCDd()
        {
            string S1, S2, mVTcGTCCDd;
            mVTcGTCCDd = "";
            S1 = "(" + Diengiai(Daytuong) + "+" + Diengiai(Daytuong + BenTc1) + ")*" + Diengiai(Caoh1) + "/2";
            S2 = "(" + Diengiai(Daytuong) + "+" + Diengiai(Daytuong + BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mVTcGTCCDd = "2*(" + S1 + "+" + S2 + ")/2*" + Diengiai(DaiTC()) + "/" + Math.Round(Math.Cos(Goca1), 3);
                if (Mrongtuong > 0)
                {
                    mVTcGTCCDd = mVTcGTCCDd + "+2*" + S1 + "*" + Diengiai(Mrongtuong);
                }

            }
            else
            {
                mVTcGTCCDd = "(" + S1 + "+" + S2 + ")/2*" + Diengiai((Double)Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi))) + "/" + Math.Round(Math.Cos(Goca1), 3);
                mVTcGTCCDd = mVTcGTCCDd + "+(" + S1 + "+" + S2 + ")/2*" + Diengiai((Double)Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi))) + "/" + Math.Round(Math.Cos(Goca2), 3);
                if (Mrongtuong > 0)
                {
                    mVTcGTCCDd = mVTcGTCCDd + "+2*" +S1 + "*" + Diengiai(Mrongtuong);   
                }
            }
            return mVTcGTCCDd;
        }
        Double VTcVgoc()
        {
            Double  S1, S2;
            Double mVtc = new double();
            S1 = (Diengiai(Daytuong) + Diengiai(Daytuong + BenTc1)) * Diengiai(Caoh1) / 2;
            S2 = (Diengiai(Daytuong) + Diengiai(Daytuong + BenTc2)) * Diengiai(CaoH2) / 2;
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mVtc = 2 * (S1 + S2) / 2 * Diengiai(DaiTC());
                if (Mrongtuong > 0)
                {
                    mVtc = mVtc + 2 * S1 * Diengiai(Mrongtuong);
                }

            }
            else
            {
                mVtc = mVtc + (S1 + S2) / 2 * Diengiai((Double)Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)));
                mVtc = mVtc + (S1 + S2) / 2 * Diengiai((Double)Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)));
                if (Mrongtuong > 0)
                {
                    mVtc = mVtc + 2 * S1 * Diengiai(Mrongtuong);
                }
            }
            return Math.Round(mVtc, 2);
        }
        String VTcVgocDd()
        {
            string S1, S2, mVTcVgocDd;
            mVTcVgocDd = "";
            S1 = "(" + Diengiai(Daytuong) + "+" + Diengiai(Daytuong + BenTc1) + ")*" + Diengiai(Caoh1) + "/2";
            S2 = "(" + Diengiai(Daytuong) + "+" + Diengiai(Daytuong + BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mVTcVgocDd = "2*(" + S1 + "+" + S2 + ")/2*" + Diengiai(DaiTC());
                if (Mrongtuong > 0)
                {
                    mVTcVgocDd = mVTcVgocDd + "+2*" + S1 + "*" + Diengiai(Mrongtuong);
                }

            }
            else
            {
                mVTcVgocDd = "(" + S1 + "+" + S2 + ")/2*" + Diengiai((Double)Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)));
                mVTcVgocDd = mVTcVgocDd + "+(" + S1 + "+" + S2 + ")/2*" + Diengiai((Double)Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)));
                if (Mrongtuong > 0)
                {
                    mVTcVgocDd = mVTcVgocDd + "+2*" + S1 + "*" +Diengiai(Mrongtuong);
                }
            }
            return mVTcVgocDd;
        }
        Double VkTc()
        {
            Double X1, X2, mVkTc;
            X1 = Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
            X2 = Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mVkTc = 4 * (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X1) / 2 + 2 * (Diengiai(DaytuongT) + Diengiai(DaytuongT) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mVkTc = mVkTc + 4 * Diengiai(Mrongtuong) * Diengiai(Caoh1);
                
            }
            else
            {
                mVkTc = 2 * (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X1) / 2 + (Diengiai(DaytuongT) + Diengiai(DaytuongT) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mVkTc = mVkTc + 2 * (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X2) / 2 + (Diengiai(DaytuongD) + Diengiai(DaytuongD) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mVkTc = mVkTc + 4 * Diengiai(Mrongtuong) * Diengiai(Caoh1);
                
            }
            if (VlTc.Substring(0,2) == "BT")
            {
                return Math.Round(mVkTc, 2);
            }
            return 0;
        }
        String VkTcDd()
        {
            string mVkTcDd;
            Double X1,X2;
            X1 = Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
            X2 = Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mVkTcDd = "4*(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X1) + "/2+" + "2*(" + Diengiai(DaytuongT) + "+" + Diengiai(DaytuongT) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                if (Mrongtuong > 0)
                {
                    mVkTcDd = mVkTcDd + "+4*" + Diengiai(Mrongtuong) + "*" + Diengiai(Caoh1);
                }

            }
            else
            {
                mVkTcDd = "2*(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X1) + "/2+(" + Diengiai(DaytuongT) + "+" + Diengiai(DaytuongT) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                mVkTcDd = mVkTcDd + "+2*(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X2) + "/2+(" + Diengiai(DaytuongD) + "+" + Diengiai(DaytuongD) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                if (Mrongtuong > 0)
                {
                    mVkTcDd = mVkTcDd + "+4*" + Diengiai(Mrongtuong) + "*" + Diengiai(Caoh1);
                }
            }
            return mVkTcDd;
        }

        Double TovuaTc() 
        {
            Double mTovuaTc,X1,X2,xx;
            X1 = Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
            X2 = Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);
            xx = Math.Sqrt(DaiTC() * Math.Sin(GocXien) * DaiTC() * Math.Sin(GocXien) + (Caoh1 - CaoH2) * (Caoh1 - CaoH2)) + Mrongtuong;
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mTovuaTc = 2 * (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X1) / 2 + 2 * (Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mTovuaTc = mTovuaTc + 2 * Diengiai(xx) * Diengiai(DaytuongT / Math.Sin(GocXien));
                mTovuaTc = mTovuaTc + 2 * Diengiai(Mrongtuong) * Diengiai(Caoh1);

                
            }
            else
            {
                mTovuaTc = (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X1) / 2 + (Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mTovuaTc = mTovuaTc + Diengiai(xx) * Diengiai(DaytuongT / Math.Sin(GocXien));
                mTovuaTc = mTovuaTc + (Diengiai(Caoh1) + Diengiai(CaoH2)) * Diengiai(X2) / 2 + (Diengiai(DaytuongD / Math.Sin(GocXien)) + Diengiai(DaytuongD / Math.Sin(GocXien)) + Diengiai(BenTc2)) * Diengiai(CaoH2) / 2;
                mTovuaTc = mTovuaTc + Diengiai(xx) * Diengiai(DaytuongD / Math.Sin(GocXien));
                mTovuaTc = mTovuaTc + 2 * Diengiai(Mrongtuong) * Diengiai(Caoh1); 
            }
            if (VlTc.Substring(0,3) == "DHX")
            {
                return Math.Round(mTovuaTc, 2);
            }
            return 0;
        }

        String TovuaTcDd()
        {
            string mTovuaTcDd;
            Double X1, X2, xx;
            X1 = Math.Abs(DaiTC() * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
            X2 = Math.Abs(DaiTC() * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);
            xx = Math.Sqrt(DaiTC() * Math.Sin(GocXien) * DaiTC() * Math.Sin(GocXien) + (Caoh1 - CaoH2) * (Caoh1 - CaoH2)) + Mrongtuong;
            if ((GocXien == Pi / 2) && Goca1 == Goca2)
            {
                mTovuaTcDd = "2*(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X1) + "/2+" + "2*(" + Diengiai(DaytuongT / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                mTovuaTcDd = mTovuaTcDd + "+2*" + Diengiai(xx) + "*" + Diengiai(DaytuongT / Math.Sin(GocXien));
                if (Mrongtuong > 0)
                {
                    mTovuaTcDd = mTovuaTcDd + "+2*" + Diengiai(Mrongtuong) + "*" + Diengiai(Caoh1);
                }

            }
            else
            {
                mTovuaTcDd = "(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X1) + "/2+(" + Diengiai(DaytuongT / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongT / Math.Sin(GocXien)) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                mTovuaTcDd = mTovuaTcDd + "+" + Diengiai(xx) + "*" + Diengiai(DaytuongT / Math.Sin(GocXien));
                mTovuaTcDd = mTovuaTcDd + "+(" + Diengiai(Caoh1) + "+" + Diengiai(CaoH2) + ")*" + Diengiai(X2) + "/2+(" + Diengiai(DaytuongD / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongD / Math.Sin(GocXien)) + Diengiai(BenTc2) + ")*" + Diengiai(CaoH2) + "/2";
                mTovuaTcDd = mTovuaTcDd + "+" + Diengiai(xx) + "*" + Diengiai(DaytuongD / Math.Sin(GocXien));
                if (Mrongtuong > 0)
                {
                    mTovuaTcDd = mTovuaTcDd + "+2*" + Diengiai(Mrongtuong) + "*" + Diengiai(Caoh1);
                }
            }
            return mTovuaTcDd;
        }
        //'Mong
        public Double BenTc3
        {
            get { return (CaoH2 + (DayCk - DuoiTc) * (1 / Docm - Tana)) * 1 / Doci; }
        }
        Double VmTc()
        {
            Double mVmTc = new double();
            Double Daimong;
            Daimong = (DaiTC() + DuoiTc - DayCk) * Math.Sin(GocXien);
            if (BnSobac == 0 )
            {
                if ((GocXien == Pi / 2) && Goca1 == Goca2)
                {
                    mVmTc = 2 * (Diengiai((DaytuongT + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + Diengiai(DaytuongT + BenTc3 + Morongm1 + Morongm2)) * Diengiai(Daimong) / 2 * Diengiai(Daymong);

                }
                else
                {
                    mVmTc = (Diengiai((DaytuongT + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + Diengiai(DaytuongT + BenTc3 + Morongm1 + Morongm2)) * Diengiai(Daimong) / 2 * Diengiai(Daymong);
                    mVmTc = mVmTc + (Diengiai((DaytuongD + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + Diengiai(DaytuongD + BenTc3 + Morongm1 + Morongm2)) * Diengiai(Daimong) / 2 * Diengiai(Daymong);

                }
            }
            else
            {
                Double Chieurong;
                long i;
                for (i = 0; i < BnSobac - 1; i++)
                {
                    Chieurong = (DaytuongT + DaytuongD) / 2 + Morongm1 + Morongm2 + (Caoh1 + i * BnCao - (i + 1) * BnRong / Docm) / Doci;
                    if (i < BnSobac - 1 )
                    {
                        mVmTc = mVmTc + 2 * (Diengiai(BnRong) * Diengiai(Daymong) + Diengiai(BnCao) * Diengiai(Daysan)) * Diengiai(Chieurong);
                    }
                    else
                    {
                        mVmTc = mVmTc + 2 * Diengiai(Rongbaccuoi - DayCk) * Diengiai(Daymong) * Diengiai(Chieurong);
                    }
                }
            }
            return Math.Round(mVmTc, 2);
        }
        String VmTcDd()
        {
            string mVmTcDd;
            Double Daimong;
            Daimong = (DaiTC() + DuoiTc - DayCk) * Math.Sin(GocXien);
            if (BnSobac == 0)
            {
                if ((GocXien == Pi / 2) && Goca1 == Goca2)
                {
                    mVmTcDd = "2*(" + Diengiai((DaytuongT + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongT + BenTc3 + Morongm1 + Morongm2) + ")*" + Diengiai(Daimong) + "/2*" + Diengiai(Daymong);

                }
                else
                {
                    mVmTcDd = "(" + Diengiai((DaytuongT + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongT + BenTc3 + Morongm1 + Morongm2) + ")*" + Diengiai(Daimong) + "/2*" + Diengiai(Daymong);
                    mVmTcDd = mVmTcDd + "+" + "(" + Diengiai((DaytuongD + BenTc1 + Morongm1 + Morongm2) / Math.Sin(GocXien)) + "+" + Diengiai(DaytuongD + BenTc3 + Morongm1 + Morongm2) + ")*" + Diengiai(Daimong) + "/2*" + Diengiai(Daymong);

                }
            }
            else
            {
                mVmTcDd = "Tính bằng phương pháp phân mảnh";
            }
            return mVmTcDd;
        }
        Double VkmTc()
        {
            Double mVkmTc = new double();
            if (BnSobac == 0)
            {
                Double X1, X2;
                X1 = Math.Abs((DaiTC() + DuoiTc - DayCk) * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
                X2 = Math.Abs((DaiTC() + DuoiTc - DayCk) * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);
                if ((GocXien == Pi / 2) && Goca1 == Goca2)
                {
                    mVkmTc = 4 * Diengiai(X1 + Mrongtuong) * Diengiai(Daymong);

                }
                else
                {
                    mVkmTc = 2 * Diengiai(X1 + Mrongtuong) * Diengiai(Daymong);
                    mVkmTc = mVkmTc + 2 * Diengiai(X2 + Mrongtuong) * Diengiai(Daymong);

                }
            }
            else
            {
                Double Chieurong;
                long i;
                for (i = 0; i < BnSobac - 1; i++)
                {
                    Chieurong = (DaytuongT + DaytuongD) / 2 + Morongm1 + Morongm2 + (Caoh1 + i * BnCao - (i + 1) * BnRong / Docm) / Doci;
                    if (i < BnSobac - 1 )
                    {
                        mVkmTc = mVkmTc + 4 * Diengiai(BnRong) * Diengiai(Daymong) + 4 * Diengiai(BnCao) * Diengiai(Daysan);
                    }
                    else
                    {
                        mVkmTc = mVkmTc + 4 * Diengiai(Rongbaccuoi - DayCk) * Diengiai(Daymong);
                    }

                }
            }
            if (VlTc.Substring(0,2) == "BT" )
            {
                return Math.Round(mVkmTc, 2);
            }
            return 0;
        }
        String VkmTcDd()
        {
            string mVkmTcDd;
            Double X1, X2;
            if (BnSobac == 0)
            {
                X1 = Math.Abs((DaiTC() + DuoiTc - DayCk) * Traiphai + MoTc1 * Math.Tan(Gocdoi)) / Math.Cos(Goca1);
                X2 = Math.Abs((DaiTC() + DuoiTc - DayCk) * Traiphai - MoTc2 * Math.Tan(Gocdoi)) / Math.Cos(Goca2);

                if ((GocXien == Pi / 2) && Goca1 == Goca2)
                {
                    mVkmTcDd = "4*" + Diengiai(X1 + Mrongtuong) + "*" + Diengiai(Daymong);

                }
                else
                {
                    mVkmTcDd = "2*" + Diengiai(X1 + Mrongtuong) + "*" + Diengiai(Daymong);
                    mVkmTcDd = mVkmTcDd + "+2*" + Diengiai(X2 + Mrongtuong) + "*" + Diengiai(Daymong);

                }
            }
            else
            {
                mVkmTcDd = "Tính bằng phương pháp phân mảnh";
            }
            return mVkmTcDd;
        }
        //'San cong
        public Double Daisan
        {
            get { return DaiTC() + Mrongtuong + DuoiTc - DayCk - MrongT; }
        }
        public Double Rongsan1(Boolean Conghop = false)
        {
            return (BeRong(Conghop) - 2 * Morongm2) / Math.Sin(GocXien);
        }
        public Double Rongsan2(Boolean Conghop = false)
        {
            return Rongsan1(Conghop) + (DaiTC() - (DayCk - DuoiTc)) * (Tana1X + Tana2X) / Math.Sin(GocXien);
        }
        Double VSancong(Boolean Conghop = false)
        {
            Double mVSancong=new double();
            //'San cong
            if (BnSobac == 0)
            {
                mVSancong = (Diengiai(Rongsan1(Conghop)) + Diengiai(Rongsan2(Conghop))) / 2 * Diengiai(Daisan * Math.Sin(GocXien)) * Diengiai(Daysan);

            }
            else
            {
                Double Chieudai;
                long i;
                for (i = 0; i < BnSobac - 1; i++)
                {
                    Chieudai = Diengiai(Rongsan1(Conghop) * Math.Sin(GocXien)) + (i + 1) * Diengiai(BnRong) * (Tana1X + Tana2X);
                    if (i < BnSobac - 1 )
                    {
                        mVSancong = mVSancong + Diengiai(BnRong + BnCao) * Diengiai(Daysan) * Chieudai;
                    }
                    else
                    {
                        mVSancong = mVSancong + Diengiai(Rongbaccuoi - DayCk) * Diengiai(Daysan) * Diengiai(Rongsan2(Conghop) * Math.Sin(GocXien));
                    }
                }
                // 'Go tieu nang
                mVSancong = mVSancong + Sogotieunang * Diengiai(RongGotieunang + RongdGotieunang) / 2 * Diengiai(CaoGotieunang) * Diengiai(DaiGotieunang);

            }
            //'Chan khay
            mVSancong = mVSancong + Diengiai(DayCk) * Diengiai(SauCk) * Diengiai(RongSanT(Conghop) + 2 * MorCk);
            return Math.Round(mVSancong, 2);
        }
        String VSanCongDd(Boolean Conghop = false)
        {
            String mVSancongDd;
            if (BnSobac == 0)
            {
                mVSancongDd = "(" + Diengiai(Rongsan1(Conghop)) + "+" + Diengiai(Rongsan2(Conghop)) + ")/2*" + Diengiai(Daisan * Math.Sin(GocXien)) + "*" + Diengiai(Daysan);
                mVSancongDd = mVSancongDd + "+" + Diengiai(DayCk) + "*" + Diengiai(SauCk) + "*" + Diengiai(RongSanT(Conghop) + 2 * MorCk);

            }
            else
            {
                mVSancongDd = "Tính bằng phương pháp phân mảnh";
            }

            return mVSancongDd;
        }
        Double VkSancong(Boolean Conghop = false)
        {
            Double mVkSancong;
            //'    'Van khuon chan khay
            mVkSancong = 2 * Diengiai(SauCk) * Diengiai((RongSanT(Conghop) + 2 * MorCk) / Math.Sin(GocXien));
            if (BnSobac > 0)
            {
                Double Chieudai;
                long i;
                for (i = 0; i < BnSobac - 2; i++)
                {
                    Chieudai = Diengiai(Rongsan1(Conghop) * Math.Sin(GocXien)) + (i + 1) * Diengiai(BnRong) * (Tana1X + Tana2X);
                    mVkSancong = mVkSancong + Diengiai(Daysan) * Chieudai;
                }
            }
            if (VlTc.Substring(0, 2) == "BT")
                return Math.Round(mVkSancong, 2);
            return 0;
        }
        String VkSanCongDd(Boolean Conghop = false)
        {
            string mVkSancongDd;
            if (BnSobac == 0)
            {
                mVkSancongDd = "2*" + Diengiai(SauCk) + "*" + Diengiai((RongSanT(Conghop) + 2 * MorCk) / Math.Sin(GocXien));
            }
            else
            {
                mVkSancongDd = "Tính bằng phương pháp phân mảnh";
            }
            return mVkSancongDd;
        }
        Double TovuaSancong(Boolean Conghop = false)
        {
            Double mTovuaSancong;
            mTovuaSancong = (Diengiai(Rongsan1(Conghop)) + Diengiai(Rongsan2(Conghop))) / 2 * Diengiai(Daisan * Math.Sin(GocXien));
            mTovuaSancong = mTovuaSancong + Diengiai(DayCk) * Diengiai(RongSanT(Conghop) + 2 * MorCk);
            if (VlTc.Substring(0, 3) == "DHX")
                return Math.Round(mTovuaSancong, 2);
            return 0;
            
        }
        String TovuaSancongDd(Boolean Conghop = false)
        {
            String mTovuaSancongDd;
            mTovuaSancongDd = "(" + Diengiai(Rongsan1(Conghop)) + "+" + Diengiai(Rongsan2(Conghop)) + ")/2*" + Diengiai(Daisan * Math.Sin(GocXien));
            mTovuaSancongDd = mTovuaSancongDd + "+" + Diengiai(DayCk) + "*" + Diengiai(RongSanT(Conghop) + 2 * MorCk);
            return mTovuaSancongDd;
        }
        Double Rongdemlot1(Boolean Conghop = false)
        {
            return Diengiai(Rongsan1(Conghop) + DaytuongT + DaytuongD + 2 * BenTc1 + 2 * Morongm1 + 2 * Morongm2);
        }
        Double Rongdemlot2(Boolean Conghop = false)
        {
            return Diengiai(Rongsan2(Conghop) + DaytuongT + DaytuongD + 2 * BenTc3 + 2 * Morongm1 + 2 * Morongm2);
        }
        Double VDemlot(Boolean Conghop = false)
        {
            Double mVDemlot;
            mVDemlot = (Rongdemlot1(Conghop) + Rongdemlot2(Conghop)) / 2 * Diengiai(Daisan * Math.Sin(GocXien)) * Diengiai(Lopdem);
            mVDemlot = mVDemlot + Diengiai(DayCk) * Diengiai(RongSanT(Conghop) + 2 * MorCk) * Diengiai(Lopdem);
            return Math.Round(mVDemlot, 2);
        }
        String VDemlotDd(Boolean Conghop = false)
        {
            String mVDemlotDd;
            mVDemlotDd = "(" + Rongdemlot1(Conghop) + "+" + Rongdemlot2(Conghop) + ")/2*" + Diengiai(Daisan * Math.Sin(GocXien)) + "*" + Diengiai(Lopdem);
            mVDemlotDd = mVDemlotDd + "+" + Diengiai(DayCk) + "*" + Diengiai(RongSanT(Conghop) + 2 * MorCk) + "*" + Diengiai(Lopdem);

            return mVDemlotDd;
        }

    }
}
